<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE HTML>
<html>
<head>
    <title>在线用户</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="/static/bui/css/bs3/dpl.css" rel="stylesheet" type="text/css"/>
    <link href="/static/bui/css/bs3/bui.css" rel="stylesheet" type="text/css"/>

</head>

<body>
<div class="content" style="margin: 15px">

    <div class="search-grid-container">
        <div id="grid">
        </div>

    </div>

    <script type="text/javascript" src="/static/bui/js/jquery-1.8.1.min.js"></script>
    <script type="text/javascript" src="/static/bui/js/bui.js"></script>
    <script type="text/javascript">

        BUI.use('common/search', function (Search) {
            var columns = [
                {title: 'ID', sortable: false, width: 300, dataIndex: 'id'},
                {title: '用户名', sortable: true, dataIndex: 'userName'},
                {title: 'host', width: 200, sortable: true, dataIndex: 'host'},
                {
                    title: '登陆时间',
                    sortable: true,
                    dataIndex: 'start',
                    width: 150,
                    renderer: BUI.Grid.Format.datetimeRenderer
                },
                {
                    title: '最后操作',
                    sortable: true,
                    dataIndex: 'last',
                    width: 150,
                    renderer: BUI.Grid.Format.datetimeRenderer
                },
                {
                    title: '操作', width: 300, dataIndex: 'g', renderer: function (value, obj) {
                    var editStr = '<span class="grid-command btn-status" title="退出">强制退出 </span>'
                    return editStr

                }
                }
            ];

            var store = Search.createStore('/session/list.json', {
                        autoSync: true //保存数据后，自动更新
                    }),
                    gridCfg = Search.createGridCfg(columns, {
                        plugins: [ BUI.Grid.Plugins.AutoFit] // 插件形式引入多选表格
                    });


            var search = new Search({
                        store: store,
                        gridCfg: gridCfg
                    }),
                    grid = search.get('grid');


            //监听事件，删除一条记录
            grid.on('cellclick', function (ev) {
                var sender = $(ev.domTarget); //点击的Dom
                if (sender.hasClass('btn-status')) {
                    var record = ev.record;
                    $.ajax({
                        url: './forceLogout/' + record.id + ".json",
                        dataType: 'json',
                        type: "POST",
                        success: function (data) {
                            if (data.code == 2000) {
                                BUI.Message.Alert("退出成功")
                            } else {
                                BUI.Message.Alert("退出失败")
                            }
                        }
                    })
                }

            });
        });


    </script>
    <!-- script end -->
</div>
</body>
</html>
